<?php 
	include "../service/util/authenticateSession.php";
	$url = ($_SERVER['REQUEST_URI']);
	//if (!preg_match('/^id=[1-9]{1,}[0-1]*$/', substr($url, strrpos($url, "?") + 1, strlen($url))))
	//	echo "<script>window.location.href= 'index.php';</script>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>Banner</title>
	<?php 
		include("import.php");
		include_once("../service/bannerService.php");
		include "messages.properties.php";
	?>
</head>
<body>
<?php include "header.php"; ?>
<form id="form" enctype="multipart/form-data">
<!-- Container -->
<div id="container">
	<div class="shell">
		<div id="main">
			<div class="cl">&nbsp;</div>
			<!-- Content -->
			<div id="content">        
            	<?php
					$message = "";
					$class = "";
					if (isset($_GET['msg'])) $action = $_GET['msg'];
					
					if(isset($action)){
						if($action == "ok") {
							$message = $messages["addBannerSuccessfully"];
							$class = "msg msg-ok";
						}
					}
					
					if ($message == "") $class = 'msg msg-hidden';
				?>
				<div class="<?php echo $class; ?>" id="msg">
					<p><strong><?php echo $message; ?></strong></p>
					<a href="#" onclick="hideMessage();" class="close">close</a>
				</div>
				<!-- Box -->
				<div class="box">
					<!-- Box Head -->
					<div class="box-head">
						<h2>Banner</h2>
					</div>
					<!-- End Box Head -->
						<!-- Form -->
						<div class="form">
                        	<?php
								$imagePath = "../images/banner/";
								$images = array();
								$result = findAll();
								while($row = ConnectionManager::getInstance()->fetch($result)){
									//echo $row["BANNER_PATH"].$row["BANNER_ID"];
									$images[substr($row["BANNER_PATH"],0,1)] = $row["BANNER_PATH"]."/".$row["BANNER_ID"];
								}
                            ?>
							<label>(Kích thước hình 873 x 323)</label>
                            <p>
                                <label>Hình ảnh 1</label>
                                <input type="file" class="field size1" name="img1" />
                                <input type="hidden" name="hdnBannerId1" value="<?php echo substr($images[1], strrpos($images[1], "/") + 1, strlen($images[1])); ?>"/>
                                <?php 
									$path = "";
									if($images[1] != ""){
										$path = $imagePath.substr($images[1], 0, strrpos($images[1], "/"));
								?>		
                                	<img src="<?php echo $path; ?>" align="top" width="30%" height="30%"/> 
                                    <a href="#" onclick="submitForm('form', '../action/deteleImageBannerAction.php?path=<?php echo $path; ?>&id=<?php echo substr($images[1], strrpos($images[1], "/") + 1, strlen($images[1])); ?>', 'post')">X</a>
								<?php
									}
								?>
                            </p>
                            <p>
                                <label>Hình ảnh 2</label>
                                <input type="file" class="field size1" name="img2"/>
                                <input type="hidden" name="hdnBannerId2" value="<?php echo substr($images[2], strrpos($images[2], "/") + 1, strlen($images[2])); ?>"/>
                               <?php 
									$path = "";
									if($images[2] != ""){
										$path = $imagePath.substr($images[2], 0, strrpos($images[2], "/"));
								?>		
                                	<img src="<?php echo $path; ?>" align="top" width="30%" height="30%"/> 
                                    <a href="#" onclick="submitForm('form', '../action/deteleImageBannerAction.php?path=<?php echo $path; ?>&id=<?php echo substr($images[2], strrpos($images[2], "/") + 1, strlen($images[2])); ?>', 'post')">X</a>
								<?php
									}
								?>
                            </p>
                            <p>
                                <label>Hình ảnh 3</label>
                                <input type="file" class="field size1" name="img3"/>
                                <input type="hidden" name="hdnBannerId3" value="<?php echo substr($images[3], strrpos($images[3], "/") + 1, strlen($images[3])); ?>"/>
                                <?php 
									$path = "";
									if($images[3] != ""){
										$path = $imagePath.substr($images[3], 0, strrpos($images[3], "/"));
								?>		
                                	<img src="<?php echo $path; ?>" align="top" width="30%" height="30%"/> 
                                    <a href="#" onclick="submitForm('form', '../action/deteleImageBannerAction.php?path=<?php echo $path; ?>&id=<?php echo substr($images[3], strrpos($images[3], "/") + 1, strlen($images[3])); ?>', 'post')">X</a>
								<?php
									}
								?>
                            </p>
                            <p>
                                <label>Hình ảnh 4</label>
                                <input type="file" class="field size1" name="img4"/>
                                <input type="hidden" name="hdnBannerId4" value="<?php echo substr($images[4], strrpos($images[4], "/") + 1, strlen($images[4])); ?>"/>
                                <?php 
									$path = "";
									if($images[4] != ""){
										$path = $imagePath.substr($images[4], 0, strrpos($images[4], "/"));
								?>		
                                	<img src="<?php echo $path; ?>" align="top" width="30%" height="30%"/> 
                                    <a href="#" onclick="submitForm('form', '../action/deteleImageBannerAction.php?path=<?php echo $path; ?>&id=<?php echo substr($images[4], strrpos($images[4], "/") + 1, strlen($images[4])); ?>', 'post')">X</a>
								<?php
									}
								?>
                            </p>
                            <p>
                                <label>Hình ảnh 5</label>
                                <input type="file" class="field size1" name="img5"/>
                                <input type="hidden" name="hdnBannerId5" value="<?php echo substr($images[5], strrpos($images[5], "/") + 1, strlen($images[5])); ?>"/>
                                <?php 
									$path = "";
									if($images[5] != ""){
										$path = $imagePath.substr($images[5], 0, strrpos($images[5], "/"));
								?>		
                                	<img src="<?php echo $path; ?>" align="top" width="30%" height="30%"/> 
                                    <a href="#" onclick="submitForm('form', '../action/deteleImageBannerAction.php?path=<?php echo $path; ?>&id=<?php echo substr($images[5], strrpos($images[5], "/") + 1, strlen($images[5])); ?>', 'post')">X</a>
								<?php
									}
								?>
                            </p>
                            <p>
                                <label>Hình ảnh 6</label>
                                <input type="file" class="field size1" name="img6"/>
                                <input type="hidden" name="hdnBannerId6" value="<?php echo substr($images[6], strrpos($images[6], "/") + 1, strlen($images[3])); ?>"/>
                                <?php 
									$path = "";
									if($images[6] != ""){
										$path = $imagePath.substr($images[6], 0, strrpos($images[6], "/"));
								?>		
                                	<img src="<?php echo $path; ?>" align="top" width="30%" height="30%"/> 
                                    <a href="#" onclick="submitForm('form', '../action/deteleImageBannerAction.php?path=<?php echo $path; ?>&id=<?php echo substr($images[6], strrpos($images[6], "/") + 1, strlen($images[6])); ?>', 'post')">X</a>
								<?php
									}
								?>
                            </p>
						</div>
						<!-- End Form -->
						<!-- Form Buttons -->
						<div class="buttons">
                            <input type="button" class="button" value="Chấp Nhận" onclick="submitForm('form', '../action/addBannerAction.php', 'post');" />
						</div>
						<!-- End Form Buttons -->
				</div>
				<!-- End Box -->
			</div>
			<!-- End Content -->
			<div class="cl">&nbsp;</div>			
		</div>
		<!-- Main -->
	</div>
</div>
<!-- End Container -->
</form>
<?php
	include "footer.php";
	ConnectionManager::getInstance()->closeConnection();
?>
</body>
</html>
